import {fileURLToPath} from 'url'
import nunjucks from 'nunjucks'
import booksTable from '../db/books.js'
//先定义响应对象
let fn_list=async(ctx,next)=>{
    // let baseDir=new URL('../Views/books.html',import.meta.url).href;
    // let otherDir=fileURLToPath(baseDir)
    // let env=nunjucks.configure();
    // let result=env.render(otherDir,{})
    // ctx.body=result
    ctx.render('books.html',{
        books:booksTable
    })
    
}
let fn_byid=async(ctx,next)=>{
    let id=ctx.params.id
    ctx.body='某个图书信息'+id
}
let fn_add=async(ctx,next)=>{
    ctx.body='新增图书'
}
let fn_delete=async(ctx,next)=>{
    ctx.body='删除图书'
}
let fn_update=async(ctx,next)=>{
    ctx.body='修改图书'
}
//导出
export const obj={
    'get /books':fn_list,
    'get /books/:id':fn_byid,
    'post /books':fn_add,
    'delete /books':fn_delete,
    'put /books':fn_update
}
